package servlets;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;

@SuppressWarnings("serial")
public class ForeverFrameServlet extends HttpServlet {
   public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
      if (req.getRequestURI().endsWith("/time")) {
         Continuation cc = ContinuationSupport.getContinuation(req, null);
         resp.setContentType("text/html");

         while (true) {
            cc.suspend(1000); // suspend the response
            String script = "<script>\r\n" +
                            "  parent.printTime(\"" + new Date() + "\");\r\n" +
                            "</script>";
            resp.getWriter().println(script);
            resp.getWriter().flush();
         }
      }
   }
}
